//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Web;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Entities.Profile;
using DotNetNuke.Entities.Users;
using DotNetNuke.Security;
using DotNetNuke.Security.Membership;
using DotNetNuke.Security.Profile;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Mail;
using DotNetNuke.UI.Skins.Controls;
using DotNetNuke.Entities.Portals;
namespace DotNetNuke.Modules.Admin.Users
{
	partial class ManageUsers : UserModuleBase, IActionable
	{
		protected bool DisplayServices
		{
			get
			{
				object setting = UserModuleBase.GetSetting(PortalId, "Profile_ManageServices");
				return Convert.ToBoolean(setting) && !(IsEdit || User.IsSuperUser);
			}
		}
		protected string RedirectURL
		{
			get
			{
				string _RedirectURL = "";
				object setting = UserModuleBase.GetSetting(PortalId, "Redirect_AfterRegistration");
				if (Convert.ToInt32(setting) == Null.NullInteger)
				{
					if (Request.QueryString["returnurl"] != null)
					{
						_RedirectURL = HttpUtility.UrlDecode(Request.QueryString["returnurl"]);
						if (_RedirectURL.Contains("://"))
						{
							_RedirectURL = "";
						}
						if (_RedirectURL.Contains("?returnurl"))
						{
							string baseURL = _RedirectURL.Substring(0, _RedirectURL.IndexOf("?returnurl"));
							string returnURL = _RedirectURL.Substring(_RedirectURL.IndexOf("?returnurl") + 11);
							_RedirectURL = string.Concat(baseURL, "?returnurl", HttpUtility.UrlEncode(returnURL));
						}
					}
					if (String.IsNullOrEmpty(_RedirectURL))
					{
						_RedirectURL = Common.Globals.NavigateURL();
					}
				}
				else
				{
					_RedirectURL = Common.Globals.NavigateURL(Convert.ToInt32(setting));
				}
				return _RedirectURL;
			}
		}
		protected bool RequireProfile
		{
			get
			{
				object setting = UserModuleBase.GetSetting(PortalId, "Security_RequireValidProfile");
				return Convert.ToBoolean(setting) && IsRegister;
			}
		}
		protected string ReturnUrl
		{
			get { return Common.Globals.NavigateURL(TabId, "", !String.IsNullOrEmpty(UserFilter) ? UserFilter : ""); }
		}
		protected bool UseCaptcha
		{
			get
			{
				object setting = UserModuleBase.GetSetting(PortalId, "Security_CaptchaRegister");
				return Convert.ToBoolean(setting) && IsRegister;
			}
		}
		protected string UserFilter
		{
			get
			{
				string filterString = !string.IsNullOrEmpty(Request["filter"]) ? "filter=" + Request["filter"] : "";
				string filterProperty = !string.IsNullOrEmpty(Request["filterproperty"]) ? "filterproperty=" + Request["filterproperty"] : "";
				string page = !string.IsNullOrEmpty(Request["currentpage"]) ? "currentpage=" + Request["currentpage"] : "";
				if (!string.IsNullOrEmpty(filterString))
				{
					filterString += "&";
				}
				if (!string.IsNullOrEmpty(filterProperty))
				{
					filterString += filterProperty + "&";
				}
				if (!string.IsNullOrEmpty(page))
				{
					filterString += page;
				}
				return filterString;
			}
		}
		public int PageNo
		{
			get
			{
				int _PageNo = 0;
				if (ViewState["PageNo"] != null)
				{
					_PageNo = Convert.ToInt32(ViewState["PageNo"]);
				}
				return _PageNo;
			}
			set { ViewState["PageNo"] = value; }
		}
		private void BindData()
		{
			if (User != null)
			{
				if (AddUser && IsHostMenu && !this.UserInfo.IsSuperUser)
				{
					AddModuleMessage("NoUser", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning, true);
					DisableForm();
					return;
				}
				if (User.PortalID != Null.NullInteger && User.PortalID != PortalId)
				{
					AddModuleMessage("InvalidUser", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning, true);
					DisableForm();
					return;
				}
				if (User.IsSuperUser && !this.UserInfo.IsSuperUser)
				{
					AddModuleMessage("NoUser", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning, true);
					DisableForm();
					return;
				}
				if (IsEdit)
				{
					if (!IsAdmin || (User.IsInRole(PortalSettings.AdministratorRoleName) && !PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName)))
					{
						AddModuleMessage("NotAuthorized", ModuleMessage.ModuleMessageType.YellowWarning, true);
						DisableForm();
						return;
					}
				}
				else
				{
					if (!IsUser)
					{
						if (Request.IsAuthenticated)
						{
							if (!PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName))
							{
								Response.Redirect(Common.Globals.NavigateURL(PortalSettings.UserTabId, "", "UserID=" + UserInfo.UserID.ToString()), true);
							}
						}
						else
						{
							if ((User.UserID > Null.NullInteger))
							{
								AddModuleMessage("NotAuthorized", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning, true);
								DisableForm();
								return;
							}
						}
					}
				}
				if (AddUser)
				{
					if (!Request.IsAuthenticated)
					{
						BindRegister();
					}
					else
					{
						cmdRegister.Text = Localization.GetString("AddUser", LocalResourceFile);
						lblTitle.Text = Localization.GetString("AddUser", LocalResourceFile);
					}
				}
				else
				{
					if (!Request.IsAuthenticated)
					{
						trTitle.Visible = false;
					}
					else
					{
						if (IsUser && IsProfile)
						{
							trTitle.Visible = false;
						}
						else
						{
							lblTitle.Text = string.Format(Localization.GetString("UserTitle", LocalResourceFile), User.Username, User.UserID.ToString());
						}
					}
				}
				if (!Page.IsPostBack)
				{
					if ((Request.QueryString["pageno"] != null))
					{
						PageNo = int.Parse(Request.QueryString["pageno"]);
					}
					else
					{
						PageNo = 0;
					}

				}
				ShowPanel();
			}
			else
			{
				AddModuleMessage("NoUser", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning, true);
				DisableForm();
			}
		}
		private void BindMembership()
		{
			ctlMembership.User = User;
			ctlMembership.DataBind();
			AddModuleMessage("UserLockedOut", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning, ctlMembership.UserMembership.LockedOut && (!Page.IsPostBack));
			imgLockedOut.Visible = ctlMembership.UserMembership.LockedOut;
			imgOnline.Visible = ctlMembership.UserMembership.IsOnLine;
		}
		private void BindRegister()
		{
			if (UseCaptcha)
			{
				ctlCaptcha.ErrorMessage = Localization.GetString("InvalidCaptcha", this.LocalResourceFile);
				ctlCaptcha.Text = Localization.GetString("CaptchaText", this.LocalResourceFile);
			}
			if (PortalSettings.UserRegistration == (int)DotNetNuke.Common.Globals.PortalRegistrationType.NoRegistration && Request.IsAuthenticated == false)
			{
				Response.Redirect(Common.Globals.NavigateURL("Access Denied"), true);
			}
			lblTitle.Text = Localization.GetString("Register", LocalResourceFile);
			cmdRegister.Text = Localization.GetString("cmdRegister", LocalResourceFile);
			lblUserHelp.Text = Localization.GetSystemMessage(PortalSettings, "MESSAGE_REGISTRATION_INSTRUCTIONS");
			switch (PortalSettings.UserRegistration)
			{
				case (int)DotNetNuke.Common.Globals.PortalRegistrationType.PrivateRegistration:
					lblUserHelp.Text += Localization.GetString("PrivateMembership", Localization.SharedResourceFile);
					break;
				case (int)DotNetNuke.Common.Globals.PortalRegistrationType.PublicRegistration:
					lblUserHelp.Text += Localization.GetString("PublicMembership", Localization.SharedResourceFile);
					break;
				case (int)DotNetNuke.Common.Globals.PortalRegistrationType.VerifiedRegistration:
					lblUserHelp.Text += Localization.GetString("VerifiedMembership", Localization.SharedResourceFile);
					break;
			}
			lblUserHelp.Text += Localization.GetString("Required", LocalResourceFile);
			lblUserHelp.Text += Localization.GetString("RegisterWarning", LocalResourceFile);
			trHelp.Visible = true;
			pnlCaptcha.Visible = UseCaptcha;
		}
		private void BindUser()
		{
			if (AddUser)
			{
				ctlUser.ShowUpdate = false;
				CheckQuota();
			}
			ctlUser.User = User;
			ctlUser.DataBind();
			if (AddUser || (IsUser && !IsAdmin))
			{
				ctlMembership.Visible = false;
			}
			else
			{
				BindMembership();
			}
		}
		private void CheckQuota()
		{
			if (PortalSettings.Users < PortalSettings.UserQuota || UserInfo.IsSuperUser || PortalSettings.UserQuota == 0)
			{
				cmdRegister.Enabled = true;
			}
			else
			{
				cmdRegister.Enabled = false;
				if (IsRegister)
				{
					AddModuleMessage("ExceededRegisterQuota", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning, true);
				}
				else
				{
					AddModuleMessage("ExceededUserQuota", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning, true);
				}
			}
		}
		private void DisableForm()
		{
			pnlTabs.Visible = false;
			pnlUser.Visible = false;
			pnlRoles.Visible = false;
			pnlPassword.Visible = false;
			pnlProfile.Visible = false;
			pnlServices.Visible = false;
		}
		private void ShowPanel()
		{
			bool showUser = (PageNo == 0);
			bool showRoles = (PageNo == 1);
			bool showPassword = (PageNo == 2);
			bool showProfile = (PageNo == 3);
			bool showServices = (PageNo == 4);
			pnlRoles.Visible = showRoles;
			pnlPassword.Visible = showPassword;
			pnlServices.Visible = showServices;
			cmdUser.Enabled = !showUser;
			if (AddUser)
			{
				pnlTabs.Visible = false;
				if (Request.IsAuthenticated && MembershipProviderConfig.RequiresQuestionAndAnswer)
				{
					pnlUser.Visible = false;
					pnlRegister.Visible = false;
					AddModuleMessage("CannotAddUser", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning, true);
				}
				else
				{
					pnlUser.Visible = true;
					pnlRegister.Visible = true;
				}
				BindUser();
				if (RequireProfile)
				{
					pnlProfile.Visible = true;
					if (AddUser)
					{
						ctlProfile.ShowUpdate = false;
					}
					ctlProfile.User = User;
					ctlProfile.DataBind();
				}
			}
			else
			{
				pnlUser.Visible = showUser;
				pnlProfile.Visible = showProfile;
				if ((!IsAdmin && !IsUser))
				{
					cmdPassword.Visible = false;
				}
				else
				{
					cmdPassword.Enabled = !showPassword;
				}
				if ((!IsEdit || User.IsSuperUser))
				{
					cmdRoles.Visible = false;
				}
				else
				{
					cmdRoles.Enabled = !showRoles;
				}
				cmdProfile.Enabled = !showProfile;
				if ((!DisplayServices))
				{
					cmdServices.Visible = false;
				}
				else
				{
					cmdServices.Enabled = !showServices;
				}
				switch (PageNo)
				{
					case 0:
						BindUser();
						break;
					case 1:
						ctlRoles.DataBind();
						break;
					case 2:
						ctlPassword.User = User;
						ctlPassword.DataBind();
						break;
					case 3:
						ctlProfile.User = User;
						ctlProfile.DataBind();
						break;
					case 4:
						ctlServices.User = User;
						ctlServices.DataBind();
						break;
				}
			}
		}
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			ctlMembership.ID = "Membership";
			ctlMembership.ModuleConfiguration = this.ModuleConfiguration;
			ctlMembership.UserId = UserId;
			ctlUser.ID = "User";
			ctlUser.ModuleConfiguration = this.ModuleConfiguration;
			ctlUser.UserId = UserId;
			ctlRoles.ID = "SecurityRoles";
			ctlRoles.ModuleConfiguration = this.ModuleConfiguration;
			ctlRoles.ParentModule = this;
			ctlPassword.ID = "Password";
			ctlPassword.ModuleConfiguration = this.ModuleConfiguration;
			ctlPassword.UserId = UserId;
			ctlProfile.ID = "Profile";
			ctlProfile.ModuleConfiguration = this.ModuleConfiguration;
			ctlProfile.UserId = UserId;
			ctlServices.ID = "MemberServices";
			ctlServices.ModuleConfiguration = this.ModuleConfiguration;
			ctlServices.UserId = UserId;
			if (AddUser)
			{
				if (!Request.IsAuthenticated)
				{
					this.ModuleConfiguration.ModuleTitle = Services.Localization.Localization.GetString("Register.Title", this.LocalResourceFile);
				}
				else
				{
					this.ModuleConfiguration.ModuleTitle = Services.Localization.Localization.GetString("AddUser.Title", this.LocalResourceFile);
				}
			}

			cmdCancel.Click += new EventHandler(cmdCancel_Click);
			cmdLogin.Click += new EventHandler(cmdLogin_Click);
			cmdPassword.Click += new EventHandler(cmdPassword_Click);
			cmdProfile.Click += new EventHandler(cmdProfile_Click);
			cmdRegister.Click += new EventHandler(cmdRegister_Click);
			cmdRoles.Click += new EventHandler(cmdRoles_Click);
			cmdServices.Click += new EventHandler(cmdServices_Click);
			cmdUser.Click += new EventHandler(cmdUser_Click);

			ctlUser.UserCreateCompleted += new UserUserControlBase.UserCreatedEventHandler(UserCreateCompleted);
			ctlUser.UserDeleted += new UserUserControlBase.UserDeletedEventHandler(UserDeleted);
			ctlUser.UserRemoved += new UserUserControlBase.UserRemovedEventHandler(UserRemoved);
			ctlUser.UserRestored += new UserUserControlBase.UserRestoredEventHandler(UserRestored);
			ctlUser.UserUpdateCompleted += new EventHandler(UserUpdateCompleted);
			ctlUser.UserUpdateError += new UserUserControlBase.UserUpdateErrorEventHandler(UserUpdateError);
			ctlUser.UserDeleteError += new UserUserControlBase.UserUpdateErrorEventHandler(UserUpdateError);
			ctlUser.UserRemoveError += new UserUserControlBase.UserUpdateErrorEventHandler(UserUpdateError);
			ctlUser.UserRestoreError += new UserUserControlBase.UserUpdateErrorEventHandler(UserUpdateError);

			ctlServices.SubscriptionUpdated += new DotNetNuke.Modules.Admin.Security.MemberServices.SubscriptionUpdatedEventHandler(SubscriptionUpdated);
			ctlProfile.ProfileUpdateCompleted += new EventHandler(ProfileUpdateCompleted);
			ctlPassword.PasswordUpdated += new Password.PasswordUpdatedEventHandler(PasswordUpdated);
			ctlPassword.PasswordQuestionAnswerUpdated += new Password.PasswordUpdatedEventHandler(PasswordQuestionAnswerUpdated);
			ctlMembership.MembershipAuthorized += new EventHandler(MembershipAuthorized);
			ctlMembership.MembershipPasswordUpdateChanged += new EventHandler(MembershipPasswordUpdateChanged);
			ctlMembership.MembershipUnAuthorized += new EventHandler(MembershipUnAuthorized);
			ctlMembership.MembershipUnLocked += new EventHandler(MembershipUnLocked);
		}
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

			try
			{
				AddActionHandler(ModuleAction_Click);
				BindData();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void cmdCancel_Click(object sender, System.EventArgs e)
		{
			Response.Redirect(Common.Globals.NavigateURL(), true);
		}
		protected void cmdLogin_Click(object sender, System.EventArgs e)
		{
			Response.Redirect(RedirectURL, true);
		}
		private void cmdPassword_Click(object sender, System.EventArgs e)
		{
			PageNo = 2;
			ShowPanel();
		}
		private void cmdProfile_Click(object sender, System.EventArgs e)
		{
			PageNo = 3;
			ShowPanel();
		}
		protected void cmdRegister_Click(object sender, System.EventArgs e)
		{
			if (((UseCaptcha && ctlCaptcha.IsValid) || (!UseCaptcha)) && ctlUser.IsValid && ((RequireProfile && ctlProfile.IsValid) || (!RequireProfile)))
			{
				ctlUser.CreateUser();
			}
		}
		private void cmdRoles_Click(object sender, System.EventArgs e)
		{
			PageNo = 1;
			ShowPanel();
		}
		private void cmdServices_Click(object sender, System.EventArgs e)
		{
			PageNo = 4;
			ShowPanel();
		}
		private void cmdUser_Click(object sender, System.EventArgs e)
		{
			PageNo = 0;
			ShowPanel();
		}
		private void ModuleAction_Click(object sender, ActionEventArgs e)
		{
			switch (e.Action.CommandArgument)
			{
				case "ManageRoles":
					pnlRoles.Visible = true;
					pnlUser.Visible = false;
					break;
				case "Cancel":
					break;
				case "Delete":
					break;
				case "Edit":
					break;
				case "Save":
					break;
				default:
					break;
			}
		}
		private void MembershipAuthorized(object sender, System.EventArgs e)
		{
			try
			{
				AddModuleMessage("UserAuthorized", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess, true);
				if (string.IsNullOrEmpty(User.Membership.Password) && !MembershipProviderConfig.RequiresQuestionAndAnswer && MembershipProviderConfig.PasswordRetrievalEnabled)
				{
					UserInfo user = User;
					User.Membership.Password = UserController.GetPassword(ref user, "");
				}
				Mail.SendMail(User, MessageType.UserRegistrationPublic, PortalSettings);
				BindMembership();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void MembershipPasswordUpdateChanged(object sender, System.EventArgs e)
		{
			try
			{
				AddModuleMessage("UserPasswordUpdateChanged", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess, true);
				BindMembership();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		private void MembershipUnAuthorized(object sender, System.EventArgs e)
		{
			try
			{
				AddModuleMessage("UserUnAuthorized", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess, true);
				BindMembership();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		private void MembershipUnLocked(object sender, System.EventArgs e)
		{
			try
			{
				AddModuleMessage("UserUnLocked", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess, true);
				BindMembership();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		private void PasswordQuestionAnswerUpdated(object sender, Password.PasswordUpdatedEventArgs e)
		{
			PasswordUpdateStatus status = e.UpdateStatus;
			if (status == PasswordUpdateStatus.Success)
			{
				AddModuleMessage("PasswordQAChanged", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess, true);
			}
			else
			{
				AddModuleMessage(status.ToString(), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError, true);
			}
		}
		private void PasswordUpdated(object sender, Password.PasswordUpdatedEventArgs e)
		{
			PasswordUpdateStatus status = e.UpdateStatus;
			if (status == PasswordUpdateStatus.Success)
			{
				try
				{
					UserInfo accessingUser = (UserInfo)HttpContext.Current.Items["UserInfo"];
					if (accessingUser.UserID != User.UserID)
					{
						Mail.SendMail(User, MessageType.PasswordReminder, PortalSettings);
					}
					else
					{
						Mail.SendMail(User, MessageType.UserUpdatedOwnPassword, PortalSettings);
					}
					AddModuleMessage("PasswordChanged", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess, true);
				}
				catch (Exception ex)
				{
					AddModuleMessage("PasswordMailError", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning, true);
					Services.Exceptions.Exceptions.LogException(ex);
				}
			}
			else
			{
				AddModuleMessage(status.ToString(), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError, true);
			}
		}
		private void ProfileUpdateCompleted(object sender, System.EventArgs e)
		{
			if (IsUser)
			{
				Mail.SendMail(User, MessageType.ProfileUpdated, PortalSettings);
				ProfilePropertyDefinition localeProperty = User.Profile.GetProperty("PreferredLocale");
				if (localeProperty.IsDirty)
				{
					if (User.Profile.PreferredLocale == string.Empty)
					{
						Localization.SetLanguage(PortalController.GetPortalDefaultLanguage(User.PortalID));
					}
					else
					{
						Localization.SetLanguage(User.Profile.PreferredLocale);
					}

				}
			}
			Response.Redirect(Request.RawUrl, true);
		}
		private void SubscriptionUpdated(object sender, Security.MemberServices.SubscriptionUpdatedEventArgs e)
		{
			string message = Null.NullString;
			if (e.Cancel)
			{
				message = string.Format(Localization.GetString("UserUnSubscribed", this.LocalResourceFile), e.RoleName);
			}
			else
			{
				message = string.Format(Localization.GetString("UserSubscribed", this.LocalResourceFile), e.RoleName);
			}
			PortalSecurity.ClearRoles();
			AddLocalizedModuleMessage(message, DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess, true);
		}
		private void UserCreateCompleted(object sender, User.UserCreatedEventArgs e)
		{
			string strMessage = "";
			try
			{
				if (e.CreateStatus == UserCreateStatus.Success)
				{
					//hide the succesful captcha
					trCaptcha.Visible = false;
					strMessage = CompleteUserCreation(e.CreateStatus, e.NewUser, e.Notify, IsRegister);
					if (IsRegister)
					{
						if ((string.IsNullOrEmpty(strMessage)))
						{
							Response.Redirect(RedirectURL, true);
						}
						else
						{
							object setting = UserModuleBase.GetSetting(PortalId, "Redirect_AfterRegistration");
							if (Convert.ToInt32(setting) == Null.NullInteger)
							{
								DisableForm();
								cmdRegister.Visible = false;
								cmdLogin.Visible = true;
							}
							else
							{
								Response.Redirect(RedirectURL, true);
							}
							DisableForm();
							cmdRegister.Visible = false;
							cmdLogin.Visible = true;
						}
					}
					else
					{
						Response.Redirect(ReturnUrl, true);
					}
				}
				else
				{
					AddLocalizedModuleMessage(UserController.GetUserCreateStatus(e.CreateStatus), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError, true);
				}
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void UserDeleted(object sender, User.UserDeletedEventArgs e)
		{
			try
			{
				Response.Redirect(ReturnUrl, true);
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}


		/// -----------------------------------------------------------------------------
		/// <summary>
		/// UserRestored runs when the User has been deleted
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <history>
		/// 	[aprasad]	2/15/2011	created
		/// </history>
		/// -----------------------------------------------------------------------------
		protected void UserRestored(object sender, User.UserRestoredEventArgs e)
		{
			try
			{
				Response.Redirect(ReturnUrl, true);
				//Module failed to load
			}
			catch (Exception exc)
			{
				Exceptions.ProcessModuleLoadException(this, exc);
			}
		}

		/// -----------------------------------------------------------------------------
		/// <summary>
		/// UserRemoved runs when the User has been deleted
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <history>
		/// 	[aprasad]	2/15/2011	created
		/// </history>
		/// -----------------------------------------------------------------------------
		protected void UserRemoved(object sender, User.UserRemovedEventArgs e)
		{
			try
			{
				Response.Redirect(ReturnUrl, true);
				//Module failed to load
			}
			catch (Exception exc)
			{
				Exceptions.ProcessModuleLoadException(this, exc);
			}
		}

		private void UserUpdateCompleted(object sender, System.EventArgs e)
		{
			Response.Redirect(Request.RawUrl, true);
		}
		private void UserUpdateError(object sender, User.UserUpdateErrorArgs e)
		{
			AddModuleMessage(e.Message, DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError, true);
		}
		public ModuleActionCollection ModuleActions
		{
			get
			{
				ModuleActionCollection Actions = new ModuleActionCollection();
				if (!IsProfile)
				{
					if (!AddUser)
					{
						Actions.Add(GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, LocalResourceFile), ModuleActionType.AddContent, "", "add.gif", EditUrl(), false, SecurityAccessLevel.Admin, true, false);
						if (ProfileProviderConfig.CanEditProviderProperties)
						{
							Actions.Add(GetNextActionID(), Localization.GetString("ManageProfile.Action", LocalResourceFile), ModuleActionType.AddContent, "", "icon_profile_16px.gif", EditUrl("ManageProfile"), false, SecurityAccessLevel.Admin, true, false);
						}
						Actions.Add(GetNextActionID(), Localization.GetString("Cancel.Action", LocalResourceFile), ModuleActionType.AddContent, "", "lt.gif", ReturnUrl, false, SecurityAccessLevel.Admin, true, false);
					}
				}
				return Actions;
			}
		}
	}
}
